﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/">
    <object-views>
      <xsl:for-each select="/document/menu-item">
        <xsl:call-template name="tpl-export-action-menu">
          <xsl:with-param name="node" select="."/>          
        </xsl:call-template>
      </xsl:for-each>
      <xsl:for-each select="/document/menu-item">
        <xsl:call-template name="tpl-export-action">
          <xsl:with-param name="node" select="."/>
        </xsl:call-template>
      </xsl:for-each>
    </object-views>
  </xsl:template>

  <xsl:template name="tpl-export-action-menu">
    <xsl:param name="node"/>
    <xsl:param name="parent"/>
    <action-menu>
      <xsl:attribute name="name">
        <xsl:value-of select="$node/@name"/>
      </xsl:attribute>
      <xsl:attribute name="title">
        <xsl:value-of select="$node/@title"/>
      </xsl:attribute>
      <xsl:if test="$parent != ''">
        <xsl:attribute name="parent">
          <xsl:value-of select="$parent"/>
        </xsl:attribute>
      </xsl:if>
    </action-menu>
    <xsl:for-each select="$node/menu-item">
      <xsl:call-template name="tpl-export-action-menu">
        <xsl:with-param name="node" select="."/>
        <xsl:with-param name="parent" select="@name"/>
      </xsl:call-template>
    </xsl:for-each>
  </xsl:template>
  <xsl:template name="tpl-export-action">
    <xsl:param name="node"/>
    <xsl:if test="@action != ''">
      <action-view>
        <xsl:attribute name="title">
          <xsl:value-of select="@title"/>
        </xsl:attribute>
        <xsl:attribute name="name">
          <xsl:value-of select="@action"/>
        </xsl:attribute>
        <xsl:for-each select="$node/views/view">
          <view>
            <xsl:attribute name="type">
              <xsl:value-of select="@type"/>
            </xsl:attribute>
            <xsl:attribute name="name">
              <xsl:value-of select="@name"/>
            </xsl:attribute>
          </view>
        </xsl:for-each>
      </action-view>
    </xsl:if>
    
    <xsl:for-each select="$node/menu-item">
      <xsl:call-template name="tpl-export-action">
        <xsl:with-param name="node" select="."/>
      </xsl:call-template>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>
